package com.bocom.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

/**
 * @author gusuchen
 * Created in 2018-05-22 17:15
 * Description:
 */
@ToString
@AllArgsConstructor
public enum ApiStatus {
    /**
     * 成功
     */
    SUCCESS("000", "请求成功！"),
    ERROR("099", "系统异常！");

    @Getter
    private final String code;
    @Getter
    private final String message;

    public static ApiStatus valueOf(int statusCode) {
        ApiStatus status = resolve(statusCode);
        if (status == null) {
            throw new IllegalArgumentException("没有存在对应的枚举类");
        }
        return status;
    }

    public static ApiStatus resolve(int statusCode) {
        for (ApiStatus status : values()) {
            if (status.getCode().equals(statusCode)) {
                return status;
            }
        }
        return null;
    }
}

